﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace QLKDS.Forms
{
    public partial class frmConfigDatabase : DevExpress.XtraEditors.XtraForm
    {
        public frmConfigDatabase()
        {
            InitializeComponent();
        }

        private void wizardControl1_FinishClick(object sender, CancelEventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void txtDbServer_EditValueChanged(object sender, EventArgs e)
        {
            if (this.txtDbServer.Text.Trim() != String.Empty)
            {
                this.dxepDbServer.ClearErrors();
            }
        }

        private void txtDbUsername_EditValueChanged(object sender, EventArgs e)
        {
            if (this.txtDbUsername.Text.Trim() != String.Empty)
            {
                this.dxepDbUsername.ClearErrors();
            }
        }

        private void txtDbPassword_EditValueChanged(object sender, EventArgs e)
        {
            if (this.txtDbPassword.Text.Trim() != String.Empty)
            {
                this.dxepDbPassword.ClearErrors();
            }
        }

        private void txtDbName_EditValueChanged(object sender, EventArgs e)
        {
            if (this.txtDbName.Text.Trim() != String.Empty)
            {
                this.dxepDbName.ClearErrors();
            }
        }

        private void wizardControl1_NextClick(object sender, DevExpress.XtraWizard.WizardCommandButtonClickEventArgs e)
        {
            if (e.Page == wizardPage1)
            {
                if (this.txtDbServer.Text.Trim() == String.Empty)
                {
                    this.dxepDbServer.SetError(this.txtDbServer, "Tên máy chủ không được bỏ trống");
                    this.txtDbServer.Focus();
                    e.Handled = true;
                    return;
                }
                else if (this.txtDbUsername.Text.Trim() == String.Empty)
                {
                    this.dxepDbUsername.SetError(this.txtDbUsername, "Tên đăng nhập không được bỏ trống");
                    this.txtDbUsername.Focus();
                    e.Handled = true;
                    return;
                }
                else if (this.txtDbPassword.Text.Trim() == String.Empty)
                {
                    this.dxepDbPassword.SetError(this.txtDbPassword, "Mật khẩu không được bỏ trống");
                    this.txtDbPassword.Focus();
                    e.Handled = true;
                    return;
                }
                else if (this.txtDbName.Text.Trim() == String.Empty)
                {
                    this.dxepDbName.SetError(this.txtDbName, "Tên cở sở dữ liệu không được bỏ trống");
                    this.txtDbName.Focus();
                    e.Handled = true;
                    return;
                }
            }
        }
    }
}